package cn.com.shopec.erp.system.common;

import org.hibernate.Hibernate;

import cn.com.shopec.erp.system.constant.SystemConstant;
import cn.com.shopec.erp.system.entity.Menu;

/**
 * 
 * @ClassName MenuUtils
 * @Description 菜单工具类
 * @author chengui
 * @date 2013-6-3 上午10:06:35
 */
public class MenuUtils {
	
	/**
	 * 
	 * @MethodName getMenuStructure
	 * @Description 计算子菜单的结构字符串
	 * @author chengui
	 * @date 2013-6-3 上午10:17:19
	 * @param pMenu
	 * @return String
	 * @throws Exception
	 */
	public static String getMenuStructure(Menu pMenu) throws Exception {
		Hibernate.initialize(pMenu.getMenus());
		String pStructure = pMenu.getStructure();
		int sufixStructure = SystemConstant.MENU_SIZE_START + pMenu.getMenus().size();
		return pStructure + "-" + sufixStructure;
	}
	
	/**
	 * 
	 * @MethodName getMenuStructure
	 * @Description 计算顶级菜单的结构字符串
	 * @author chengui
	 * @date 2013-6-3 上午10:35:14
	 * @param rootSize
	 * @return String
	 */
	public static String getMenuStructure(int rootSize) {
		return SystemConstant.ROOT_SIZE_START + "-" + rootSize;
	}
	
	/**
	 * 
	 * @MethodName getMenuLevel
	 * @Description 通过父菜单级别获得子菜单级别
	 * @author chengui
	 * @date 2013-6-4 下午4:27:09
	 * @param pMenu
	 * @return
	 */
	public static int getMenuLevel(Menu pMenu) {
		return pMenu.getLevel() + 1;
	}

}
